package main

import (
	"api_online/config"
	"api_online/core/parse"
	"api_online/data"
	"api_online/https"
	"fmt"
	"log"
	"net/http"
)

/*
接口文档生成工具,侧重生成,并且提供各种格式的导出.
 */



func init() {
	// 初始化路由
	https.InitRouter()
	log.Println("初始化路由完成")

	// 解析语法树
	parse.InitSyntaxTree()
	log.Println("解析语法树完成")

	// 尝试从 持久化中加载参数及返回值
	_ = data.Cache.LoadResultCache()
	_ = data.Cache.LoadParamVal()
	log.Println("参数及返回值加载完成")
}

func main() {
	log.Println("服务开启")

	port := config.Config.HttpPort
	if port == "" {
		port = "8081"
	}
	address := fmt.Sprintf("localhost:%s", port)

	// 开启服务
	log.Println(fmt.Sprintf("请访问: http://%s", address))
	err := http.ListenAndServe(address, nil)
	if err != nil {
		return 
	}
}